package com.chenjie.executor.day15;

/**
 * packageName com.chenjie.executor.day15
 *
 * @author chenjie
 * @version JDK 8
 * @className Student (此处以class为例)
 * @date 2024/5/28
 * @description TODO
 */
public class Student {
    private static String name;

    public void setName(String name) {
        synchronized (this){
            if(null==this.name){
                this.name = name;
                System.out.println("setName="+name);
            }

        }
    }

    public void setName0(String name) {
        synchronized (new Student()){
            if(null==this.name){
                this.name = name;
                System.out.println("setName="+name);
            }

        }
    }

    public void setName1(String name) {
        synchronized (this.getClass()){
            if(null==this.name){
                this.name = name;
                System.out.println("setName="+name);
            }

        }
    }

    public synchronized void setName2(String name) {
            if(null==this.name){
                this.name = name;
                System.out.println("setName="+name);
            }


    }

    public  static  synchronized void setName3(String name) {
        if(null==Student.name){
            Student.name = name;
            System.out.println("setName="+name);
        }


    }

}
